﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
namespace SchoolManagementSystem.Details
{
    //Kỳ hạn đóng học phí theo khóa học
    public partial class Class_FeeTimeUC : DetailUC
    {
        public Class_FeeTimeUC()
        {
            InitializeComponent();
            this.ObjectName = "kỳ hạn đóng học phí";
            this.Code = "Course_Fee";
            this.Type = new Class_FeeTime();
            commandBarUC1.cmdnew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
        }

       
        protected override long DetailDisplay()
        {
            commandBarUC1.cmdnew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            Class_FeeTime data = new Class_FeeTime();
            if (ID > 0)
            {
                data = (Class_FeeTime)RegisterService.RegisterServices.Class_FeeService.GetByID(ID);
               
            }
            if (data.Type == 1)
            {
                groupControl_time2.Visible = false;
                groupControl_time3.Visible = false;
                groupControl_time4.Visible = false;
                groupControl_time5.Visible = false;
                groupControl_time6.Visible = false;
                groupControl_time1.Visible = true;
               
               
            }
            if (data.Type == 2)
            {
                groupControl_time3.Visible = false;
                groupControl_time4.Visible = false;
                groupControl_time6.Visible = false;
                groupControl_time5.Visible = false;
                groupControl_time1.Visible = true;
                groupControl_time2.Visible = true;
               
            }
            if (data.Type == 3)
            {
                groupControl_time4.Visible = false;
                groupControl_time6.Visible = false;
                groupControl_time5.Visible = false;
                groupControl_time1.Visible = true;
                groupControl_time2.Visible = true;
                groupControl_time3.Visible = true;
               
            }
            if (data.Type == 4)
            {
                groupControl_time6.Visible = false;
                groupControl_time5.Visible = false;
                groupControl_time1.Visible = true;
                groupControl_time2.Visible = true;
                groupControl_time3.Visible = true;
                groupControl_time4.Visible = true;
               
            }
            if (data.Type == 6)
            {
                groupControl_time1.Visible = true;
                groupControl_time2.Visible = true;
                groupControl_time3.Visible = true;
                groupControl_time4.Visible = true;
                groupControl_time6.Visible = true;
                groupControl_time5.Visible = true;
            }

            dateEdit_start1.DateTime = data.StartDate1;
            dateEdit_start2.DateTime = data.StartDate2;
            dateEdit_start3.DateTime = data.StartDate3;
            dateEdit_start4.DateTime = data.StartDate4;
            dateEdit_start5.DateTime = data.StartDate5;
            dateEdit_start6.DateTime = data.StartDate6;

            dateEdit_end1.DateTime = data.EndDate1;
            dateEdit_end2.DateTime = data.EndDate2;
            dateEdit_end3.DateTime = data.EndDate3;
            dateEdit_end4.DateTime = data.EndDate4;
            dateEdit_end5.DateTime = data.EndDate5;
            dateEdit_end6.DateTime = data.EndDate6;

            spinEdit_Money1.EditValue = data.Money1;
            spinEdit_Money2.EditValue = data.Money2;
            spinEdit_Money3.EditValue = data.Money3;
            spinEdit_Money4.EditValue = data.Money4;
            spinEdit_Money5.EditValue = data.Money5;
            spinEdit_Money6.EditValue = data.Money6;

            return ID;

        }



        protected override long Save()
        {
            Class_FeeTime data = new Class_FeeTime();
            if (ID > 0)
            {
                data = (Class_FeeTime)RegisterService.RegisterServices.Class_FeeService.GetByID(ID);
            }

            data.ClassID = long.Parse(SearchString.Replace("'", "").Replace("ClassID=", "").Trim());

              data.StartDate1=  dateEdit_start1.DateTime ;
              data.StartDate2 = dateEdit_start2.DateTime ;
              data.StartDate3  =dateEdit_start3.DateTime ;
              data.StartDate4  =dateEdit_start4.DateTime  ;
              data.StartDate5   =dateEdit_start5.DateTime ;
              data.StartDate6  =dateEdit_start6.DateTime ;

             data.EndDate1 = dateEdit_end1.DateTime ;
             data.EndDate2   =dateEdit_end2.DateTime ;
             data.EndDate3 =  dateEdit_end3.DateTime ;
             data.EndDate4   =dateEdit_end4.DateTime ;
             data.EndDate5 =  dateEdit_end5.DateTime ;
             data.EndDate6 = dateEdit_end6.DateTime;

             data.Money1 = int.Parse(spinEdit_Money1.EditValue.ToString());
             data.Money2 = int.Parse(spinEdit_Money2.EditValue.ToString());
             data.Money3 = int.Parse(spinEdit_Money3.EditValue.ToString());
             data.Money4 = int.Parse(spinEdit_Money4.EditValue.ToString());
             data.Money5 = int.Parse(spinEdit_Money5.EditValue.ToString());
             data.Money6 = int.Parse(spinEdit_Money6.EditValue.ToString());

            ID = RegisterService.RegisterServices.Class_FeeService.Save(data);

            return ID;
        }

        public override bool Delete(long SelectedID)
        {
            return RegisterService.RegisterServices.Class_FeeService.Delete(RegisterService.RegisterServices.Class_FeeService.GetByID(SelectedID));

        }

        private void Course_FeeTimeUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl_time1.Controls);
            AddTextChanged(groupControl_time2.Controls);
            AddTextChanged(groupControl_time3.Controls);
            AddTextChanged(groupControl_time4.Controls);
            AddTextChanged(groupControl_time5.Controls);
            AddTextChanged(groupControl_time6.Controls);
        }

  
     

    }
}
